package com.jindy.module.copy.service.impl;

import java.util.List;

import com.jindy.common.constant.HttpStatus;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.domain.model.LoginUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jindy.module.copy.mapper.CopyMapper;
import com.jindy.module.copy.domain.Copy;
import com.jindy.module.copy.service.ICopyService;

/**
 * 抄送Service业务层处理
 * 
 * @author jindy
 * @date 2023-03-28
 */
@Service
public class CopyServiceImpl implements ICopyService 
{
    @Autowired
    private CopyMapper copyMapper;

    /**
     * 查询抄送
     * 
     * @param id 抄送主键
     * @return 抄送
     */
    @Override
    public Copy selectCopyById(Long id)
    {
        return copyMapper.selectCopyById(id);
    }

    /**
     * 查询抄送列表
     * 
     * @param copy 抄送
     * @return 抄送
     */
    @Override
    public List<Copy> selectCopyList(Copy copy)
    {
        return copyMapper.selectCopyList(copy);
    }

    /**
     * 新增抄送
     * 
     * @param copy 抄送
     * @return 结果
     */
    @Override
    public int insertCopy(Copy copy)
    {
        copy.setCreateTime(DateUtils.getNowDate());
        return copyMapper.insertCopy(copy);
    }

    /**
     * 修改抄送
     * 
     * @param copy 抄送
     * @return 结果
     */
    @Override
    public int updateCopy(Copy copy)
    {
        copy.setUpdateTime(DateUtils.getNowDate());
        return copyMapper.updateCopy(copy);
    }

    /**
     * 批量删除抄送
     * 
     * @param ids 需要删除的抄送主键
     * @return 结果
     */
    @Override
    public int deleteCopyByIds(Long[] ids)
    {
        return copyMapper.deleteCopyByIds(ids);
    }

    /**
     * 删除抄送信息
     * 
     * @param id 抄送主键
     * @return 结果
     */
    @Override
    public int deleteCopyById(Long id)
    {
        return copyMapper.deleteCopyById(id);
    }

    /**
     * 修改审批抄送管理
     * @param copy
     * @return
     */
    @Override
    public AjaxResult updateBizCopyBySerialNum(Copy copy) {
        //获取当前人
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return new AjaxResult(HttpStatus.UNAUTHORIZED,"请先登录");
        }
        copy.setUpdateBy(loginUser.getUsername());
        copy.setCopyerStatus("1");
        copy.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
        if(copyMapper.updateBizCopyBySerialNum(copy)<1){
            return new AjaxResult(HttpStatus.ERROR,"修改失败");
        }
        return AjaxResult.success();
    }
}
